import time
from selenium.webdriver.common.by import By
from common.Utils import FroumDriver
class FroumDetail:
    driver = ""
    url = ""
    def __init__(self):
        self.driver = FroumDriver.driver
        #添加 隐式等待
        self.driver.implicitly_wait(5)
        self.url = "http://127.0.0.1:9580/index.html"
        self.driver.get(self.url)

    #测试帖子详情页元素
    def DetailTest(self):
        #登录状态下，通过详情页的url访问，只能访问到论坛首页，不能进入详情页，这里点击标题进入详情页
        self.driver.find_element(By.CSS_SELECTOR,"#artical-items-body > div:nth-child(1) > div > div.col > div.text-truncate > a > strong").click()
        #检查 用户头像 是否存在
        self.driver.find_element(By.CSS_SELECTOR,"#article_details_author_avatar")
        #检查 帖子内容 是否存在
        self.driver.find_element(By.CSS_SELECTOR,"#details_article_content")
        #检查 帖子发布时间 是否存在
        self.driver.find_element(By.CSS_SELECTOR,"#details_article_createTime")
        #检查 ”发私信“ 按钮是否存在
        self.driver.find_element(By.CSS_SELECTOR,"#btn_details_send_message")
        #检查 ”点赞“ 按钮是否存在
        self.driver.find_element(By.CSS_SELECTOR,"#details_btn_like_count")
        #屏幕截图
        time.sleep(1)
        FroumDriver.getScreenShot()

    #论坛系统的评论区属于不可交互元素（待完善）

    #私信功能测试
    def SendPMTest(self):
        #（1）发送内容不为空
        # 登录状态下，通过详情页的url访问，只能访问到论坛首页，不能进入详情页，这里点击标题进入详情页
        self.driver.find_element(By.CSS_SELECTOR,"#artical-items-body > div:nth-child(1) > div > div.col > div.text-truncate > a > strong").click()
        #点击 “私信” 按钮
        self.driver.find_element(By.CSS_SELECTOR,"#btn_details_send_message").click()
        #编辑私信内容
        self.driver.find_element(By.CSS_SELECTOR,"#index_message_receive_content").send_keys("你好呀")
        #点击发送
        self.driver.find_element(By.CSS_SELECTOR,"#btn_index_send_message").click()
        #检查系统是否提示发送成功
        expect="成功"
        text=self.driver.find_element(By.CSS_SELECTOR, "body > div.jq-toast-wrap.bottom-right > div").text
        print(text)
        assert expect==text
        time.sleep(1)
        FroumDriver.getScreenShot()

        #（2）发送内容为空
        # 点击 “私信” 按钮
        self.driver.find_element(By.CSS_SELECTOR, "#btn_details_send_message").click()
        # 编辑私信内容
        self.driver.find_element(By.CSS_SELECTOR, "#index_message_receive_content").send_keys("你好呀")
        # 点击发送
        self.driver.find_element(By.CSS_SELECTOR, "#btn_index_send_message").click()
        # 检查系统是否提示 “请输入要发送的内容”
        expect = "警告"
        text = self.driver.find_element(By.CSS_SELECTOR, "body > div.jq-toast-wrap.bottom-right > div").text
        print(text)
        assert expect == text
        time.sleep(1)
        FroumDriver.getScreenShot()

















